/**
 * Next.js演示服务器应用
 */
const express = require('express');
const path = require('path');
const config = require('./config');
const { setupMiddleware, setupErrorHandlers, createStaticFilesMiddleware } = require('./middleware');
const setupRoutes = require('./routes');

/**
 * 创建Express应用
 * @returns {Express.Application} Express应用实例
 */
const createApp = () => {
  const app = express();
  
  // 设置基础中间件
  setupMiddleware(app, config);
  
  // 设置路由
  setupRoutes(app);
  
  // 设置静态文件处理
  const staticMiddlewares = createStaticFilesMiddleware(config.staticFilesPath);
  staticMiddlewares.forEach(middleware => app.use(middleware));
  
  // 设置错误处理
  setupErrorHandlers(app);
  
  return app;
};

module.exports = createApp; 